import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:keep_account/utils/global.dart';
import 'package:keep_account/utils/widget_util.dart';

import '../utils/getx_util.dart';

class UserProfile extends StatefulWidget {
  const UserProfile({super.key});

  @override
  State<StatefulWidget> createState() => _UserProfileState();
}

class _UserProfileState extends State<UserProfile> {

  var _phone = "";

  @override
  void initState(){
    super.initState();
    _getPhone();
  }
  void _getPhone() async {
    _phone = await Global().getPhone();
    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("我的",style: TextStyle(color: Theme.of(context).colorScheme.primary)),),
      body: SingleChildScrollView(
        padding: const EdgeInsets.only(left: 15,right: 15),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Container(
              alignment: Alignment.centerLeft,
              padding: const EdgeInsets.only(top: 5,bottom: 5,left: 15),
              margin: const EdgeInsets.only(top: 200),
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.circular(15)
              ),
              child: Text("您好: $_phone",style: const TextStyle(fontSize: 20),),
            ),
            const SizedBox(width: double.infinity, height: 20,),
            const SizedBox(width: double.infinity, height: 20,),
            ListTile(
              title: const Text("年月日视图",style: TextStyle(fontSize: 20,fontWeight: FontWeight.w600),),
              contentPadding: const EdgeInsets.only(),
              subtitle: const Text("按照折线图的方式查看年月日工资数据"),
              leading: Icon(Icons.bar_chart_rounded,color: Theme.of(context).colorScheme.primary,),
              trailing: const Icon(Icons.chevron_right_rounded),
              onTap: (){
                toNamed("/ymd_work_records");
              },
            ),
            Container(
              margin: const EdgeInsets.only(top: 80),
              child: ElevatedButton(
                onPressed: () async {
                  await Global().setPhone("");
                  await Global().setToken("");
                  offAllNamed("/user_login");
                },
                child: const Text("退出登录")
              ),
            ),
          ],
        ),
      ),
    );
  }

}